<!-- 任务模态框组件 -->
<template>
  <view class="task-modal" v-if="visible">
    <!-- 遮罩层 -->
    <view class="modal-mask" @click="onMaskClick"></view>
    
    <!-- 弹窗内容 -->
    <view class="modal-content">
      <task-form
        :taskData="taskData"
        :isEdit="isEdit"
        :groupId="groupId"
        @submit="onSubmit"
        @cancel="onCancel"
      />
    </view>
  </view>
</template>

<script>
import TaskForm from './TaskForm.vue';

export default {
  name: 'TaskModal',
  components: {
    TaskForm
  },
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    // 编辑模式下传入的任务数据
    taskData: {
      type: Object,
      default: () => ({})
    },
    // 是否为编辑模式
    isEdit: {
      type: Boolean,
      default: false
    },
    // 当前分组ID
    groupId: {
      type: String,
      default: ''
    },
    // 是否允许点击遮罩关闭
    closeOnClickMask: {
      type: Boolean,
      default: true
    }
  },
  methods: {
    // 点击遮罩层
    onMaskClick() {
      if (this.closeOnClickMask) {
        this.onCancel();
      }
    },
    
    // 提交表单
    onSubmit(taskData) {
      this.$emit('submit', taskData);
    },
    
    // 取消操作
    onCancel() {
      this.$emit('cancel');
    }
  }
}
</script>

<style lang="scss" scoped>
.task-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-mask {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  animation: fade-in 0.2s ease;
}

.modal-content {
  position: relative;
  width: 80%;
  max-width: 600rpx;
  z-index: 1000;
  border-radius: 12px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
  animation: modal-in 0.3s ease;
  overflow: hidden;
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: scale(0.8);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
</style> 